Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failure when enabling bracketed paste #9353

Merged
merged 4 commits into from
Jan 18, 2024

Conversation

jigypeper
Copy link
Contributor

@jigypeper jigypeper commented Jan 16, 2024

match statement instead of crash for #9336

@jigypeper
Copy link
Contributor Author

not sure i've handled the ok match arm correctly :/

@the-mikedavis the-mikedavis changed the title match instead of crash Handle failure when enabling bracketed paste Jan 16, 2024
@@ -131,12 +131,22 @@ where
{
fn claim(&mut self, config: Config) -> io::Result<()> {
terminal::enable_raw_mode()?;
execute!(
match execute!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The execute! for EnableBracketedPaste should be separated from the other terminal commands so that if the other commands fail we bail.

Also we need to track whether the terminal supports bracketed paste so that we can decide not to send DisableBracketedPaste in restore:

match execute!(self.buffer, EnableBracketedPaste) {
    Err(err) if err.kind() == io::ErrorKind::Unsupported => {
        log::warn!("Bracketed paste is not supported on this terminal.");
        self.supports_bracketed_paste = false;
    }
    Err(err) => return Err(err),
    Ok(_) => (),
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force_restore also needs to be modified so that it calls

let _ = execute!(stdout, DisableBracketedPaste);

rather than bailing when it isn't supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do i need to modify the trait method here to accept self?
or is there another way to check the supports_bracketed_paste field?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force_restore is called from a panic handler so there's no way to pass in information like the crossterm backend. Instead we have to execute the commands directly against stdout and in this case we can execute DisableBracketedPaste and then just discard the Result so that we continue restoring the terminal even when it gives Err(Error::Unsupported)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we just bind it to the throwaway and remove it from the execute! at the end?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly 👍

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@the-mikedavis the-mikedavis added the S-waiting-on-review Status: Awaiting review from a maintainer. label Jan 16, 2024
@pascalkuthe pascalkuthe merged commit 9c56afe into helix-editor:master Jan 18, 2024
6 checks passed
hamrik pushed a commit to hamrik/helix that referenced this pull request Jan 27, 2024
* match instead of crash

* pulling bracketedpaste out, refactor, tracking for bracketed paste

* sending disable bracketed paste only when supports true

* move disable bracketed paste to throwaway
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
* match instead of crash

* pulling bracketedpaste out, refactor, tracking for bracketed paste

* sending disable bracketed paste only when supports true

* move disable bracketed paste to throwaway
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
* match instead of crash

* pulling bracketedpaste out, refactor, tracking for bracketed paste

* sending disable bracketed paste only when supports true

* move disable bracketed paste to throwaway
Vulpesx pushed a commit to Vulpesx/helix that referenced this pull request Jun 7, 2024
* match instead of crash

* pulling bracketedpaste out, refactor, tracking for bracketed paste

* sending disable bracketed paste only when supports true

* move disable bracketed paste to throwaway
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
* match instead of crash

* pulling bracketedpaste out, refactor, tracking for bracketed paste

* sending disable bracketed paste only when supports true

* move disable bracketed paste to throwaway
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants